package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品管理
 */
@RestController
@RequestMapping("/admin/dish")
@Slf4j
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     */
    @PostMapping
    public Result save(@RequestBody DishDTO dishDTO){
        dishService.save(dishDTO);
        return Result.success();
    }

    /**
     * 编辑菜品
     */
    @PutMapping
    public Result update(@RequestBody DishDTO dishDTO){
        dishService.update(dishDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    public Result<String> startOrStop(@PathVariable("status") Integer status, Long id){
        dishService.startOrStop(status,id);
        return Result.success();
    }

    /**
     * 菜品分页查询
     */
    @GetMapping("page")
    public Result<PageResult> page(DishPageQueryDTO dishDTO){
        PageResult result = dishService.page(dishDTO);
        return Result.success(result);
    }

    /**
     * 菜品批量删除
     */
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){//TODO 直接封装成了List
        log.info("菜品批量删除：{}",ids);
        dishService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 菜品查询
     */
    @GetMapping("/{id}")
    public Result<DishVO> pagebyId(@PathVariable Long id){
        DishVO result = dishService.pagebyId(id);
        return Result.success(result);
    }

}
